'use strict';

const { Controller } = require('ee-core');
const Log = require('ee-core/log');
const Services = require('ee-core/services');
const { saveFileStreamToLocal } = require("../utils/fileTools");
const { random } = require("lodash");
const { resOk } = require("../utils/tools");


class UserController extends Controller {
	constructor (props) {
		super(props);

	}

	// 上传文件到指定目录中
	async uploadFile (params) {
		try {
			let { single } = params;
			let res
			if (single) {
				res = await Services.get('user').singleFileUpload(params)
			} else {
				res = await Services.get('user').zipFileUpload(params)
			}
			return resOk(res)
		} catch (e) {
			Log.error(e);
		}
	}

	async uploadAllFile (params) {
		try {
			const res = await Services.get('user').uploadAllFile(params)
			return resOk(res)
		} catch (e) {
			Log.error(e);
		}
	}

	async getAllUser (params) {
		try {
			return await Services.get('user').getAllUser(params)
		} catch (e) {
			Log.error(e);
		}
	}

	async analysisWord () {
		try {
			return await Services.get('user').analysisWord()
		} catch (e) {
			Log.error(e);
		}
	}

	async uploadBatchFile (params) {
		Log.info('[preload] uploadBatchFile()',params)
		try {
			return await Services.get('user').uploadBatchFile(params)
		} catch (e) {
			Log.error(e);
		}
	}

	async refresh(){
		try {
			return await Services.get('user').refresh()
		} catch (e) {
			Log.error(e);
		}
	}
}


UserController.toString = () => '[class UserController]';
module.exports = UserController;
